package com.sgb.knowledgeshare.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.knowledgeshare.R;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Created by fq on 2020/9/25 0025
 * Description：
 */
public class UserVideoEditAdaoter extends BaseRecycleAdapter<VideoBean> {

    public UserVideoEditAdaoter(Context context, List<VideoBean> datas) {
        super(context, R.layout.item_video_edit, datas);
    }


    @Override
    public void convert(ItemViewHolder holder, VideoBean bean) {
        //holder.setBinding(BR.viewModel, bean);
        RelativeLayout rleditchoice = holder.itemView.findViewById(R.id.rl_edit_choice);//是否选中布局
        ImageView editimagev = holder.itemView.findViewById(R.id.edit_imagev);//是否选中的图标
        ImageView editlogo = holder.itemView.findViewById(R.id.edit_logo);//封面图
        TextView edittime = holder.itemView.findViewById(R.id.edit_time);//时间
//        根据状态动态设置是否选中状态
        if (bean.isSelect() == true) {
            editimagev.setImageResource(R.mipmap.share_user_video_select);
        } else {
            editimagev.setImageResource(R.mipmap.share_user_video_no);
        }
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.share_classify_loading)//图片加载出来前，显示的图片
                .fallback( R.mipmap.share_classify_failure) //url为空的时候,显示的图片
                .error(R.mipmap.share_classify_failure);//图片加载失败后，显示的图片
        Glide.with(context).load(bean.getCover()).apply(options).into(editlogo);
      //  edittime.setText(DateUtils.generateTime(bean.getDuration()));
        edittime.setText(bean.getDuration());
        //是否选中状态的布局
        rleditchoice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onvideolistbean.onClickBean(bean.getVideoId());
            }
        });
    }

    private OnVideoListBean onvideolistbean;

    public void setOnvideolistbean(OnVideoListBean onvideolistbean) {

        this.onvideolistbean = onvideolistbean;
    }

    /**
     * 定义一个接口
     */
    public interface OnVideoListBean {
        void onClickBean(String videoId);
    }
}
